home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Primer Plus
/
Java Primer Plus (Waite Group Proess)(1996).iso
/
chapter11
/
tryexample.java
< prev
next >
Wrap
Text File
|
1995-12-31
|
667b
|
34 lines
/* try and catch example */
class tryexample2 {
public static void main(String args[]) {
try {
other(); // exception will be caught from
// this call
System.out.println("Hey it worked!");
}
catch(ArithmeticException e) {
System.out.println(e.getMessage());
}
System.out.println("The calculations are complete!");
other(); // exception will not be caught
// system will issue an error and
// terminate the run
System.out.println("I never print");
}
static void other() {
int a;
a = 0;
// if (a==0) throw new NullPointerException();
a = 10/a;
}
}